package org.theonept.travian.t4a.batiments;

import java.util.List;

import org.theonept.travian.model.Compte;
import org.theonept.travian.model.Ressource;
import org.theonept.travian.model.Village;
import org.theonept.travian.t4a.R;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

/**
 * A dummy fragment representing a section of the app, but that simply displays
 * dummy text.
 */
public class BatimentsSectionFragment extends Fragment implements AdapterView.OnItemClickListener {
	/**
	 * The fragment argument representing the section number for this fragment.
	 */
	public static final String ARG_SECTION_NUMBER = "section_number";
	private ListView ressourceListView;
	private ListBatimentsAdapter listRessourcesAdapter;
	private Compte compte;
	private Village village;

	public BatimentsSectionFragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_compte_message, container, false);
		ressourceListView = (ListView) rootView.findViewById(R.id.listMessage);
		if (listRessourcesAdapter == null) {
			listRessourcesAdapter = new ListBatimentsAdapter(getActivity());
		}
		this.compte = (Compte) getArguments().getSerializable("compte");
		this.village = (Village) getArguments().getSerializable("village");
		List<Ressource> ressources = (List<Ressource>) getArguments().getSerializable("ressources");
		if (ressources != null) {
			setData(ressources);
		}
		ressourceListView.setAdapter(listRessourcesAdapter);
		ressourceListView.setOnItemClickListener(this);
		return rootView;
	}

	public void setData(List<Ressource> ressources) {
		listRessourcesAdapter.setData(ressources);
		listRessourcesAdapter.clear();
		listRessourcesAdapter.addAll(ressources);

	}

	@Override
	public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
		// Ressource ressource = listRessourcesAdapter.getItem(position);
		// Intent intentRessource = new Intent(getActivity(),
		// RessourcesActivity.class);
		// intentRessource.putExtra("village", village);
		// intentRessource.putExtra("compte", compte);
		// intentRessource.putExtra("ressource",
		// listRessourcesAdapter.getItem(position));
		// startActivity(intentRessource);
	}
}